﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Web;
using System.Web.Script.Services;
using System.Web.Security;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging;

namespace TractRecord
{
    public class TractRecordPage: Page
    {

        #region Properties
        
        /// <summary>
        /// The name of the application, primarily for use by Inf functionality.
        /// </summary>
        protected static string ApplicationName
        {
            get { return "TractRecord.Web"; }
        }

        /// <summary>
        /// The name of the screen/page, primarily for use by Inf functionality.
        /// </summary>
        protected string ScreenName
        {
            get { return Page.GetType().Name.Replace("_aspx", ".aspx"); }
        }

        protected static LogWriter Logger
        {
            get { return EnterpriseLibraryContainer.Current.GetInstance<LogWriter>(); }
        }

        #endregion

         #region Constructors

        /// <summary>
        /// Creates a new instance of the class.
        /// </summary>
        public TractRecordPage() : base()
        {
            this.Init += new EventHandler(TractRecordBasePage_Init);
            this.Error += new EventHandler(TractRecordBasePage_Error);            
        }

        #endregion

        #region Event Handlers

        /// <summary>
        /// Handles the event that occurs when the page is initializing.
        /// </summary>
        /// <param name="sender">The object that triggered the event.</param>
        /// <param name="e">Information about the event.</param>
        private void TractRecordBasePage_Init(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// Handles the event that occurs when an unhandled error occurs.
        /// </summary>
        /// <param name="sender">The object that triggered the event.</param>
        /// <param name="e">Information about the event.</param>
        private void TractRecordBasePage_Error(object sender, EventArgs e)
        {
            // get the exception object that represents the error
            Exception ex = Server.GetLastError();

            // log the error
            Code.Common.Log(ex.ToString(), "TractRecordBasePage_Error", 100, 0, System.Diagnostics.TraceEventType.Warning, string.Format(CultureInfo.InvariantCulture, "An unhandled exception has occurred in the web application on {0}.", Server.MachineName)); 
           
            // redirect to a friendly error page
            //Context.Items["InfLogId"] = infLogId;
            Context.Items["Exception"] = ex;
            //Server.Transfer("~/UnhandledError.aspx");
        }

        #endregion
    }
}